package com.mujin.keji.collectionsystem.module.updata.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.updata.contract.UploadContract;
import com.mujin.keji.collectionsystem.module.updata.dto.ShowVisitUserDto;
import com.mujin.keji.collectionsystem.utils.EmptyUtils;

import java.util.List;


/**
 * 待上传的数据列表适配器
 *
 * @author weishixiong
 * @Time 2018-05-4
 */

public class UpDataListAdapter extends RecyclerView.Adapter<UpDataListAdapter.ViewHolder> {
    private Activity mContext;
    private List<ShowVisitUserDto> datas;//需要展示的集合
    private CustomItemClickListener listener;

    public UpDataListAdapter(Activity context, List<ShowVisitUserDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_up_data, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

            holder.itemView.setVisibility(View.VISIBLE);
            holder.tvDate.setText(datas.get(position).getVisitUserDtoList().get(0).getTaskTime());
            holder.tvAdress.setText(datas.get(position).getVisitUserDtoList().get(0).getTaskAdress());
            holder.tvName.setText(datas.get(position).getVisitUserDtoList().get(0).getName());
            holder.tvAccount.setText((datas.get(position).getVisitUserDtoList().size()) + "");


    }



    @Override
    public int getItemCount() {


        return datas==null?0:datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivHead;
        private TextView tvName;
        private TextView tvDate;
        private TextView tvAdress;
        private TextView tvAccount;
        private View itemView;

        public ViewHolder(final View itemView, final CustomItemClickListener listener) {
            super(itemView);
            this.itemView = itemView;
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvAdress = (TextView) itemView.findViewById(R.id.tv_adress);
            tvAccount = (TextView) itemView.findViewById(R.id.tvAccount);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onItemClick(itemView, getAdapterPosition());
                }
            });
        }

    }
}
